#include <stdio.h>
#include <stdlib.h>
#define N 1000
void readFile(FILE *f)
{
    if ((f = fopen("demo.txt", "r")) == NULL)
    {
       exit(1);
    }
    //读字符
    char s[1000]; 
    char *str=s;
    int count = 0;
    while ((str = fgets(str,N,f)) != NULL)
    {
        printf("%s",str);
        count++;
        //       printf("第%d个字符\n",count);
    }
    printf("一共有%d行\n", count);
    fclose(f);
}

void writeFile(FILE *f)
{
    //写字符
    if ((f = fopen("demo.txt", "a+")) == NULL)
    {
        exit(1);
    }
    char *str = "啦啦啦啦";
    fputs(str,f);
    puts("请输入一个字符串:\n");
    char s[10];
    gets(s);
    fputs(s,f);
    fclose(f);
}
int main()
{

    FILE *f;
    readFile(f);
    writeFile(f);
    readFile(f);
    return 0;
}